package com.ga.util;

import java.util.Date;

import com.ga.model.Album;
import com.ga.model.Reply;
import com.ga.model.User;
import com.ga.model.Video;
import com.jfinal.plugin.activerecord.Db;

public class DBUtil {
	public static void datainit(){
		Db.update("truncate table users");
		Db.update("truncate table album");
		Db.update("truncate table video");
		Db.update("truncate table reply");
		//admin
		new User().set("uname", "admin@ga.com")
		.set("pwd", "admin123")
		.set("nickname", "admin")
		.set("avatar", "resources/avatar/admin.png")
		.set("question", "天王盖地虎")
		.set("answer","小鸡炖蘑菇")
		.set("description","朕乃真命天子")
		.set("active", 1)
		.set("lastmodifytime", new Date()).save();
		
		//add user test data
		for (int i = 1; i < 51; i++) {
			User user=new User();
			user.set("uname", "test"+i+"@ga.com");
			user.set("pwd", "111111");
			user.set("nickname", "test"+i);
			user.set("avatar", "resources/avatar/default0.png");
			user.set("lastmodifytime", new Date());
			user.save();
		}
		//add album test data
		for (int i = 1; i< 21;  i++) {
			Album album=new Album();
			album.set("aname", "视频专辑"+i);
			album.set("description", "视频说明"+i);
			album.set("users_id", 1);
			album.set("lastmodifytime", new Date());
			album.set("front_pic", "resources/album/default.jpg");
			album.save();
		}
		//add vido test data
		for (int i = 1; i< 51;  i++) {
			Video video=new Video();
			video.set("title", "吉他原创《冲破地平线》"+i);
			video.set("description", "一飞冲天"+i);
			video.set("videopath", "resources/video/default.mp4");
			video.set("front_pic", "resources/video/default.jpg");
			video.set("tag", "吉他原创");
			video.set("album_id", 1);
			video.set("playamount", 1000+i);
			video.set("praise", 100+i);
			video.set("status", 1);
			video.set("lastmodifytime", new Date());
			video.set("users_id", 1);
			video.save();
		}
		//add reply test data
		for (int i = 1; i< 21;  i++) {
			Reply reply=new Reply();
			reply.set("content", i+"头一次评论啊，好紧张啊，该怎么说啊，打多少字才显的有文采啊，好激动啊！");
			reply.set("users_id", 3);
			reply.set("video_id", 1);
			reply.set("parentid", 0);
			reply.set("status", 2);
			reply.save();
		}
		for (int i = 1; i< 21;  i++) {
			Reply reply2=new Reply();
			reply2.set("content", i+"我只是路过来看看");
			reply2.set("users_id", 1);
			reply2.set("video_id", 1);
			reply2.set("parentid", i);
			reply2.set("status", 2);
			reply2.save();
		}
	}
}
